home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- Smaller Installer © 1996 Bill Goodman, All Rights Reserved
- *******************************************************************************
-
- Password Hook Example
-
- This installer hook procedure prompts the user to enter a password when the
- INSTALL button is clicked. The password is specified in the "Password" field
- of the SI Builder project document and may be any string up to 255 characters
- in length.
-
- To build this hook procedure, compile this code and create a code resource
- (Type:SICR, ID:501, non-preloaded, nonpurgeable, unlocked, unprotected,
- non-sysheap). Add this resource to the "PasswordHook.rsrc" file. Copy all the
- resources in "PasswordHook.rsrc" to your installer's resource file.
- ******************************************************************************/
-
- // This file is compatible with version 2.1 of the universal headers
- #include <Dialogs.h>
-
- #ifdef __MWERKS__
- #include <A4Stuff.h>
- #endif
-
- #ifdef THINK_C
- #include <SetUpA4.h>
- #endif
-
- #include "SIHookProc.h"
-
-
- /******************************************************************************
- Module Internal Function Prototypes
- ******************************************************************************/
- void BeginOperationFunction(void);
-
-
- /******************************************************************************
- Constant Definitions
- ******************************************************************************/
- // Dialog Definitions
- #define pswdDlg 500 // Password dialog
- #define ok_pswdlg 1 // OK button
- #define stop_pswdDlg 2 // STOP button
- #define password_pswdDlg 3 // Password edit text field
-
- // Alert Definitions
- #define errorAlrt 510 // "This password is not valid. Please call 1-800-555-XXXX for assistance."
-
-
- /******************************************************************************
- Module Variable Definitions
- ******************************************************************************/
- SIHookParmBlk *gParms; // Global pointer to parameter block
- Str255 gPasswordStr; // Password string
-
-
- /*****************************************************************************/
- pascal void main(
- SIHookParmBlk *parmBlk // Pointer to parameter block
- )
- /******************************************************************************
- This is the main entry point for the installer hook procedure.
- ******************************************************************************/
- {
- #ifdef __MWERKS__
- long holdA4;
- #endif
-
- // Set up access to global variables
- #ifdef THINK_C
- RememberA0();
- SetUpA4();
- #endif
-
- #ifdef __MWERKS__
- holdA4 = SetCurrentA4();
- #endif
-
- gParms = parmBlk;
-
- switch (gParms->function)
- {
- case siHookBeginOperation:
- BeginOperationFunction();
- break;
- }
-
- // Restore original A4 value
- #ifdef THINK_C
- RestoreA4();
- #endif
-
- #ifdef __MWERKS__
- SetA4(holdA4);
- #endif
- }
-
-
- /*****************************************************************************/
- void BeginOperationFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
- "passwordPtr" Pointer to password string
- "filesRemaining" Number of files remaining to install or remove
- "bytesRemaining" Number of bytes of data remaining to install or remove
- "doingRemove" Non-zero if doing remove operation
-
- Returns:
- "passwordPtr" Pointer to password string
- "result" Hook result code (siHookNoErr, siHookQuit, siHookAbort)
-
- This function is called when the install button or the remove button is
- clicked to begin installing or removing files.
- ******************************************************************************/
- {
-
- DialogPtr dlgPtr;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short item;
-
- if (gParms->doingRemove)
- return; // Allow Remove to proceed
-
- if (gParms->passwordPtr != NULL)
- { // Password error
- StopAlert(errorAlrt, NULL);
- gParms->result = siHookQuit;
- gPasswordStr[0] = 0; // Clear invalid password
- return;
- }
-
- if (gPasswordStr[0])
- gParms->passwordPtr = gPasswordStr; // Use previously entered password
- else
- { // No previous password entered - prompt user for password
- dlgPtr = GetNewDialog(pswdDlg, NULL, (WindowPtr) -1L);
- ModalDialog(NULL, &item);
- if (item == stop_pswdDlg)
- gParms->result = siHookAbort; // User cancelled - force installer to abort
- else
- {
- GetDItem(dlgPtr, password_pswdDlg, &itemType, &itemHdl, &itemRect);
- GetIText(itemHdl, gPasswordStr);
- gParms->passwordPtr = gPasswordStr;
- }
- DisposDialog(dlgPtr);
- }
- return;
- }
-